package br.com.datasun.biblioteca.ui.listeners;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JTextField;

public class KeyListenerTamanhoCampo implements KeyListener {
	private JTextField textField;
	private int tamanhoMaximo = 0;
	
	public KeyListenerTamanhoCampo(JTextField textField, int tamanhoMaximo){
		this.textField = textField;
		this.tamanhoMaximo = tamanhoMaximo;
	}
	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void keyTyped(KeyEvent e) {
		String texto = textField.getText();
		if(texto.length() >= tamanhoMaximo){
			e.consume();
		}

	}

}
